<template>
  <a-modal
    title="修改密码"
    :visible="isShow"
    @ok="handleSubmit"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @cancel="handleCancel"
    width="40%"
    :destroyOnClose="true"
  >
    <a-form :form="form">
      <a-form-item
        label="旧密码："
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-input-password
          v-decorator="[
            'oldPassword',
            {
              rules: [{ required: true, message: '请输入旧密码' }],
              validateTrigger: 'blur'
            }
          ]"
          placeholder="请输入旧密码"
        >
          <a-icon
            slot="prefix"
            type="lock"
            :style="{ color: 'rgba(0,0,0,.25)' }"
          />
        </a-input-password>
      </a-form-item>
      <a-form-item
        label="新密码："
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-input-password
          v-decorator="[
            'newPassword',
            {
              rules: [{ required: true, message: '请输入新密码' }],
              validateTrigger: 'blur'
            }
          ]"
          placeholder="请输入新密码"
        >
          <a-icon
            slot="prefix"
            type="lock"
            :style="{ color: 'rgba(0,0,0,.25)' }"
          />
        </a-input-password>
      </a-form-item>
      <a-form-item
        label="确认新密码："
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-input-password
          v-decorator="[
            'newPassword1',
            {
              rules: [{ required: true, message: '请输入确认新密码' }],
              validateTrigger: 'blur'
            }
          ]"
          placeholder="请输入确认新密码"
        >
          <a-icon
            slot="prefix"
            type="lock"
            :style="{ color: 'rgba(0,0,0,.25)' }"
          />
        </a-input-password>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { page } from "@/api";
export default {
  // props: ['show', 'disposeIds'],
  data() {
    return {
      form: this.$form.createForm(this),
      confirmLoading: false,
      isShow: false,
      getPars: {
        currentPage: 1,
        pageSize: 10,
        name: ""
      }
    };
  },
  mounted() {},
  methods: {
    show(id) {
      confirmLoading: false;
      this.isShow = true;
      this.personId = id;
    },
    handleCancel() {
      this.isShow = false;
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          if (values.newPassword !== values.newPassword1) {
            this.$message.warning("新密码和确认密码不匹配！");
            return;
          }
          this.confirmLoading = true;
          let params = Object.assign(values, { id: this.personId });
          page
            .updatePassword(params)
            .then(res => {
              if (res.data.code === -1) {
                this.$message.warning(res.data.message);
              } else {
                this.isShow = false;
                this.$emit("addSuccess");
                this.$message.success("修改密码成功");
              }
              this.confirmLoading = false;
            })
            .catch(() => {
              this.isShow = false;
              this.confirmLoading = false;
              this.$message.warning("修改密码失败");
            });
        }
      });
    }
  }
};
</script>
